<?php
class MFormSelect extends MFormElement {

    protected $_options;

    public function __construct($name, $form) {
        parent::__construct($name, $form);
        $this->_options = array();
    }

    public function addOption($content){
        $object = new MFormSelectOption($this->_form, $content);
        array_push($this->_options, $object);
        return $object;
    }

    public function setMultiple($multiple = true){
        ($multiple)?$this->setHtmlOption('multiple', 'multiple'):$this->removeHtmlOption('multiple');
        return $this;
    }

    public function render() {
//        $return = '<p>'.self::EOL;
        $return = '';
        if (!empty($this->_label)){
            $return .= self::TAB.'<label for="'.$this->getHtmlOption('name').'"'.(($this->getForm()->useFormee)?' class="form-lbl"':NULL).'>'.
                    $this->_label.(($this->_required)?'<span class="form-req"> * </span>':NULL).
                    '</label>'.self::EOL;
        }
        $return .= '<select'.$this->renderHtmlOptions().'>';
        foreach ($this->_options as $option){
            $return .= self::TAB.$option->render().self::EOL;
        }
        $return .= '</select>'.self::EOL;
//        $return .= '</p>'.self::EOL;
        return $return;
    }
    
}

class MFormSelectOption extends MHtmlElement {
    protected $_form;
    protected $_content;

    public function __construct($form, $content) {
        $this->_form = $form;
        $this->_content = $content;
    }

    public function render() {
        $return = '<option'.$this->renderHtmlOptions().'>'.$this->_content.'</option>';
        return $return;
    }

    public function setValue($value){
        $this->setHtmlOption('value', $value);
        return $this;
    }

    public function setLabel($label){
        $this->setHtmlOption('label', $label);
        return $this;
    }

    public function setDisabled($disabled = true){
        ($disabled)?$this->setHtmlOption('disabled', 'disabled'):$this->removeHtmlOption('disabled');
        return $this;
    }

    public function setSelected($selected = true){
        ($selected)?$this->setHtmlOption('selected', 'selected'):$this->removeHtmlOption('selected');
        return $this;
    }

}
?>
